package com.xinjiang.electricpower.timer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.InputStream;

/**
 * @Author D_TZ
 * @Date 2023/3/115:32
 * @ClassName XinZhuangOrderTask
 * @Desription
 **/
@Component
@Slf4j
public class XinZhuangOrderTask {



    /**
     * 执行营销新装kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 23 * * ?")  //每凌晨05:00小时执行一次
    public void runWorkOrderKjb() {
        try {
            log.info("执行营销新装定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("xinzhuang/new_work_order.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, null, in);
            log.info("执行营销新装定时任务结束~~~~");
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }

    /**
     * 执行营销低压新装kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 7 * * ?")  //每凌晨07:00小时执行一次
    public void lowRunWorkOrderKjb() {
        try {
            log.info("执行营销新装[低压]定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("xinzhuang/low_work_order.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, null, in);
            log.info("执行营销新装[低压]定时任务结束~~~~");
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }

    /**
     * 执行营销高压新装kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 6 * * ?")  //每凌晨06:00小时执行一次
    public void highRunWorkOrderKjb() {
        try {
            log.info("执行营销新装[高压]定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("xinzhuang/high_work_order.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, null, in);
            log.info("执行营销新装[高压]定时任务结束~~~~");
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
    /**
     * 执行工单推送kjb文件
     *
     * @return
     */
//    @Async
    @Scheduled(cron = "0 0 5 * * ?")  //每凌晨05:00小时执行一次
    public void pushRunWorkOrderKjb() {
        try {
            log.info("执行工单推送定时任务开启~~~~");
            InputStream in = this.getClass().getClassLoader().getResourceAsStream("pushdata/data_push.ktr");
            //执行对应ktr 文件转换
            KettleQuartz.runKettleTransfer(null, null, in);
            log.info("执行工单推送定时任务结束~~~~");
        } catch (Exception e) {
            log.error("拉取{}工单数据异常 {}", e);
        }
    }
}
